﻿using BarManager.Core.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BarManager.Infrastructure.Data.Mapping
{
    public class PromocionDetalleMap : EntityTypeConfiguration<PromocionDetalle>
    {
        public PromocionDetalleMap()
        {
            // Primary Key
            this.HasKey(t => new { t.ProductoId, t.PromocionId });

            // Properties
            this.Property(t => t.ProductoId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.PromocionId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
                        
            // Table & Column Mappings
            this.ToTable("PromocionesDetalle");
            this.Property(t => t.ProductoId).HasColumnName("ProductoId");
            this.Property(t => t.PromocionId).HasColumnName("PromocionId");
            this.Property(t => t.Cantidad).HasColumnName("Cantidad");
            this.Ignore(t => t.Guid);

            // Relationships
            this.HasRequired(t => t.Producto)
                .WithMany(t => t.PromocionDetalleList)
                .HasForeignKey(d => d.ProductoId)
                .WillCascadeOnDelete(false);
            this.HasRequired(t => t.Promocion)
                .WithMany(t => t.PromocionDetalleList)
                .HasForeignKey(d => d.PromocionId);

        }
    }
}
